<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>Buffer剖析 | 架构成长指南</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  
    <meta name="description" content="java技术分享，系统架构剖析，java实践分享，ai相关知识分享，chatGPT,架构成长指南">
  
  
    <meta name="keywords" content="架构成长指南，架构，java，云原生，chatGPT">
  
  
    <link rel="alternate" href="/atom.xml" title="架构成长指南" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
  
    
<link rel="stylesheet" href="/localshare/css/share.css">

  
  
    
<link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">

  
  
<meta name="generator" content="Hexo 7.0.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">架构成长指南</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        
          <a class="main-nav-link" href="/."><i class="fa fa-home"></i> 首页</a>
        
          <a class="main-nav-link" href="/archives/"><i class="fa fa-archive"></i> 归档</a>
        
          <a class="main-nav-link" href="/about/"><i class="fa fa-user"></i> 关于</a>
        
      </nav>
    </div>
    <div id="search-form">
      <div id="result-mask" class="hide"></div>
      <label><input id="search-key" type="text" autocomplete="off" placeholder="搜索"></label>
      <div id="result-wrap" class="hide">
        <div id="search-result"></div>
      </div>
      <div class="hide">
        <template id="search-tpl">
          <div class="item">
            <a href="/{path}" title="{title}">
              <div class="title">{title}</div>
              <div class="time">{date}</div>
              <div class="tags">{tags}</div>
            </a>
          </div>
        </template>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-2022/java/Buffer" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      Buffer剖析
    </h1>
  


      </header>
    
    <div class="article-meta">
      
      <span class="article-date">
  <i class="fa fa-date"></i>
  <time class="dt-published" datetime="2018-01-26T02:08:10.000Z" itemprop="datePublished">2018年01月26日</time>
</span>
      
  <div class="article-category">
    <i class="fa fa-classify"></i>
    <a class="article-category-link" href="/categories/%E5%90%8E%E7%AB%AF/">后端</a>
  </div>

      
        <span class="article-views">
  <i class="fa fa-views"></i>
  <i id="busuanzi_container_page_pv">
      <i id="busuanzi_value_page_pv"></i>
  </i>
</span>

      
      
<a href="/2018/01/26/2022/java/Buffer/#comments" class="article-comment-link">
  
    
    
    
    
    
  
  <i class="fa fa-commt"></i>
  留言
</a>


    </div>
    <div class="e-content article-entry" itemprop="articleBody">
      
        <blockquote>
<p>Buffer 类是 java.nio 的构造基础。一个 Buffer 对象是固定数量的数据的容器，其作用是一个存储器，或者分段运输区，在这里，数据可被存储并在之后用于检索。缓冲区可以被写满或释放。对于每个非布尔原始数据类型都有一个缓冲区类，即 Buffer 的子类有：ByteBuffer、CharBuffer、DoubleBuffer、FloatBuffer、IntBuffer、LongBuffer 和 ShortBuffer，是没有 BooleanBuffer 之说的。尽管缓冲区作用于它们存储的原始数据类型，但缓冲区十分倾向于处理字节。非字节缓冲区可以在后台执行从字节或到字节的转换，这取决于缓冲区是如何创建的。 </p>
</blockquote>
<span id="more"></span>
<h4 id="属性"><a href="#属性" class="headerlink" title="属性"></a>属性</h4><h6 id="容量-Capacity"><a href="#容量-Capacity" class="headerlink" title="容量(Capacity)"></a>容量(Capacity)</h6><blockquote>
<p>缓冲区能够容纳的数据元素的最大数量。这一容量在缓冲区创建时被设定，并且永远不能被改变</p>
</blockquote>
<h6 id="上界-Limit"><a href="#上界-Limit" class="headerlink" title="上界(Limit)"></a>上界(Limit)</h6><blockquote>
<p>缓冲区的第一个不能被读或写的元素。缓冲创建时，limit 的值等于 capacity 的值。假设 capacity &#x3D; 1024，我们在程序中设置了 limit &#x3D; 512，说明，Buffer 的容量为 1024，但是从 512 之后既不能读也不能写，因此可以理解成，Buffer 的实际可用大小为 512。</p>
</blockquote>
<h6 id="位置-Position"><a href="#位置-Position" class="headerlink" title="位置(Position)"></a>位置(Position)</h6><blockquote>
<p>下一个要被读或写的元素的索引。位置会自动由相应的 get() 和 put() 函数更新。 这里需要注意的是positon的位置是从0开始的。</p>
</blockquote>
<h6 id="标记-Mark"><a href="#标记-Mark" class="headerlink" title="标记(Mark)"></a>标记(Mark)</h6><blockquote>
<p>一个备忘位置。标记在设定前是未定义的(undefined)。使用场景是，假设缓冲区中有 10 个元素，position 目前的位置为 2(也就是如果get的话是第三个元素)，现在只想发送 6 - 10 之间的缓冲数据，此时我们可以 buffer.mark(buffer.position())，即把当前的 position 记入 mark 中，然后 buffer.postion(6)，此时发送给 channel 的数据就是 6 - 10 的数据。发送完后，我们可以调用 buffer.reset() 使得 position &#x3D; mark，因此这里的 mark 只是用于临时记录一下位置用的。</p>
</blockquote>
<h4 id="方法"><a href="#方法" class="headerlink" title="方法"></a>方法</h4><h6 id="flip"><a href="#flip" class="headerlink" title="flip()"></a>flip()</h6><blockquote>
<p>flip方法将Buffer从写模式切换到读模式。调用flip()方法会将position设回0，并将limit设置成之前position的值,这样就可以读取之前所有写入的数据</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">public final Buffer flip() &#123;</span><br><span class="line">    limit = position;</span><br><span class="line">    position = 0;</span><br><span class="line">    mark = -1;</span><br><span class="line">    return this;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>示例</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ByteBuffer buffer = ByteBuffer.allocate(1024); </span><br><span class="line">buffer.put((byte)&#x27;H&#x27;).put((byte)&#x27;e&#x27;).put((byte)&#x27;l&#x27;).put((byte)&#x27;l&#x27;).put((byte)&#x27;o&#x27;); </span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>此时，position &#x3D; 5，limit &#x3D; capacity &#x3D; 1024。现在我们要从正确的位置从 buffer 读数据，我们可以把 position 置为 0，那么字符串的结束位置在哪呢？这里上界该出场了。如果把上界设置成当前 position 的位置，即 5，那么 limit 就是结束的位置。上界属性指明了缓冲区有效内容的末端。人工实现翻转：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">buffer.limit(buffer.position()).position(0); </span><br></pre></td></tr></table></figure>
<p>但系统提供了一个非常便利的函数：buffer.flip()。<br>另外，</p>
<h6 id="rewind"><a href="#rewind" class="headerlink" title="rewind()"></a>rewind()</h6><blockquote>
<p>rewind() 函数与 flip() 相似，但不影响上界属性，它只是将位置值设回 0。在进行buffer读操作的时候，一般都会使用buffer.flip()函数。  </p>
</blockquote>
<h6 id="hasRemaining"><a href="#hasRemaining" class="headerlink" title="hasRemaining()"></a>hasRemaining()</h6><blockquote>
<p>读取缓冲区时告诉你是否已经达到缓冲区的上界</p>
</blockquote>
<ul>
<li>示例</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">for (int i = 0; buffer.hasRemaining(); i++) &#123; </span><br><span class="line">    myByteArray[i] = buffer.get(); </span><br><span class="line">&#125; </span><br></pre></td></tr></table></figure>
<p>很明显，上面的代码，每次都要判断元素是否到达上界。我们可以做：改变后的读取过程</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">int count = buffer.hasRemaining(); </span><br><span class="line">for (int i = 0; i &lt; count; i++) &#123; </span><br><span class="line">    myByteArray[i] = buffer.get(); </span><br><span class="line">&#125; </span><br></pre></td></tr></table></figure>
<h5 id="清空缓冲区"><a href="#清空缓冲区" class="headerlink" title="清空缓冲区"></a>清空缓冲区</h5><h6 id="clear"><a href="#clear" class="headerlink" title="clear()"></a>clear()</h6><blockquote>
<p> clear() 函数将缓冲区重置为空状态。它并不改变缓冲区中的任何数据元素，而是仅仅将 limit 设为容量的值，并把 position 设回 0，如果这会在写入元素的话，会覆盖原有索引位置的元素</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">public final Buffer clear() &#123;</span><br><span class="line">    position = 0;</span><br><span class="line">    limit = capacity;</span><br><span class="line">    mark = -1;</span><br><span class="line">    return this;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


<h6 id="Compact"><a href="#Compact" class="headerlink" title="Compact()"></a>Compact()</h6><blockquote>
<p>compact()方法只会清除已经读过的数据<br>示例：</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"> @Test</span><br><span class="line">    public void compactTest() &#123;</span><br><span class="line">        ByteBuffer buffer = ByteBuffer.allocate(10);</span><br><span class="line">        buffer.put((byte) &#x27;M&#x27;).put((byte) &#x27;e&#x27;).put((byte) &#x27;l&#x27;).put((byte) &#x27;l&#x27;).put((byte) &#x27;o&#x27;).put((byte) &#x27;w&#x27;);</span><br><span class="line">        //进行翻转,切换为读模式</span><br><span class="line">        buffer.flip();</span><br><span class="line">        System.out.println((char) buffer.get());</span><br><span class="line">        buffer.compact();</span><br><span class="line">        System.out.println(&quot;-------&quot;);</span><br><span class="line">        buffer.put((byte) &#x27;s&#x27;);</span><br><span class="line">        buffer.flip();</span><br><span class="line">        while (buffer.hasRemaining()) &#123;</span><br><span class="line">            System.out.println((char) buffer.get());</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">结果：    </span><br><span class="line">M</span><br><span class="line">-------</span><br><span class="line">e</span><br><span class="line">l</span><br><span class="line">l</span><br><span class="line">o</span><br><span class="line">w</span><br><span class="line">s</span><br></pre></td></tr></table></figure>
<h5 id="比较"><a href="#比较" class="headerlink" title="比较"></a>比较</h5><h6 id="equals"><a href="#equals" class="headerlink" title="equals()"></a>equals()</h6><blockquote>
<ol>
<li>缓存器类型比对</li>
<li>剩余元素数量比对</li>
<li>如果在比对前,切换为读模式flip(),那么是各元素值比对,否则是默认值比对,永远返回成功。</li>
</ol>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">public boolean equals(Object ob) &#123;</span><br><span class="line">     if (this == ob)</span><br><span class="line">         return true;</span><br><span class="line">         //类型比对</span><br><span class="line">     if (!(ob instanceof ByteBuffer))</span><br><span class="line">         return false;</span><br><span class="line">         //剩余元素数量比对</span><br><span class="line">     ByteBuffer that = (ByteBuffer)ob;</span><br><span class="line">     if (this.remaining() != that.remaining())</span><br><span class="line">         return false;</span><br><span class="line">     int p = this.position();</span><br><span class="line">     for (int i = this.limit() - 1, j = that.limit() - 1; i &gt;= p; i--, j--)</span><br><span class="line">         //剩余元素默认值比对</span><br><span class="line">         if (!equals(this.get(i), that.get(j)))</span><br><span class="line">             return false;</span><br><span class="line">     return true;</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<h6 id="compareToTest"><a href="#compareToTest" class="headerlink" title="compareToTest()"></a>compareToTest()</h6><blockquote>
<ol>
<li>比较剩余未读取的元素值,返回0 表示 </li>
<li>如果所有元素值都相等,在比较剩余,那个byte首先被读取完,即:即:(limit - postion),是否相等</li>
</ol>
</blockquote>
<h5 id="存取元素"><a href="#存取元素" class="headerlink" title="存取元素"></a>存取元素</h5><h6 id="get-byte-dst"><a href="#get-byte-dst" class="headerlink" title="get(byte[] dst)"></a>get(byte[] dst)</h6><blockquote>
<p>读取buffer数据至dst数组，如果buffer中的元素不能够填满dst，则抛出BufferUnderflowException</p>
</blockquote>
<h6 id="get-byte-dst-int-offset-int-length"><a href="#get-byte-dst-int-offset-int-length" class="headerlink" title="get(byte[] dst, int offset, int length)"></a>get(byte[] dst, int offset, int length)</h6><blockquote>
<p>读取buffer数据至dst，offer为dst存放起始位置，length为获取几个元素，如果buffer中的元素数量小于length（即不能够满足dst需要的元素数量），则抛出BufferUnderflowException</p>
</blockquote>
<h6 id="put-byte-src"><a href="#put-byte-src" class="headerlink" title="put(byte [] src)"></a>put(byte [] src)</h6><blockquote>
<p>从src数组的起始位置，读取所有元素至buffer，如果要写入的元素的数量大于buffer的可写入数量，则抛出throw new BufferOverflowException();</p>
</blockquote>
<h6 id="put-byte-src-int-offset-int-length"><a href="#put-byte-src-int-offset-int-length" class="headerlink" title="put(byte[] src, int offset, int length) {"></a>put(byte[] src, int offset, int length) {</h6><blockquote>
<p>从src数组中读取数据至buffer,offer的起始位置，length为从offer开始读取元素的数量，如果要length大于buffer的可写入数量，则抛出throw new BufferOverflowException();</p>
</blockquote>
<h5 id="创建缓冲区"><a href="#创建缓冲区" class="headerlink" title="创建缓冲区"></a>创建缓冲区</h5><h6 id="allocate-int-capacity"><a href="#allocate-int-capacity" class="headerlink" title="allocate (int capacity)"></a>allocate (int capacity)</h6><blockquote>
<p>allocate操作创建一个缓冲区对象，是由系统自动创建一个长度为capacity的数组</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">public static ByteBuffer allocate(int capacity) &#123;</span><br><span class="line">      if (capacity &lt; 0)</span><br><span class="line">          throw new IllegalArgumentException();</span><br><span class="line">      return new HeapByteBuffer(capacity, capacity);</span><br><span class="line">  &#125;</span><br><span class="line">      </span><br><span class="line"> HeapByteBuffer(int cap, int lim) &#123;            // package-private</span><br><span class="line">    //自动创建一个length为cap的数组</span><br><span class="line">   super(-1, 0, lim, cap, new byte[cap], 0);</span><br><span class="line"></span><br><span class="line">  &#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h6 id="wrap-byte-array"><a href="#wrap-byte-array" class="headerlink" title="wrap(byte[] array)"></a>wrap(byte[] array)</h6><blockquote>
<p>wrap操作创建一个缓冲区对象，但不分配任何空间来储存数据元素。它使用提供的数组作为存储空间来储存缓冲区中的数据元素。</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">public static ByteBuffer wrap(byte[] array) &#123;</span><br><span class="line">       return wrap(array, 0, array.length);</span><br><span class="line">   &#125;</span><br><span class="line">   </span><br><span class="line">public static ByteBuffer wrap(byte[] array,</span><br><span class="line">                                int offset, int length)</span><br><span class="line">&#123;</span><br><span class="line">    try &#123;</span><br><span class="line">        return new HeapByteBuffer(array, offset, length);</span><br><span class="line">    &#125; catch (IllegalArgumentException x) &#123;</span><br><span class="line">        throw new IndexOutOfBoundsException();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">   </span><br></pre></td></tr></table></figure>

<h6 id="wrap-byte-array-int-offset-int-length"><a href="#wrap-byte-array-int-offset-int-length" class="headerlink" title="wrap(byte[] array, int offset, int length)"></a>wrap(byte[] array, int offset, int length)</h6><blockquote>
<p>与wrap(byte[] array)方法一样，只是创建一个 postion为offset，limit为offset+length的缓冲区</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">char[] myArray = new char[10];</span><br><span class="line">CharBuffer charbuffer = CharBuffer.wrap (myArray, 2, 3);</span><br></pre></td></tr></table></figure>
<p>以上代码将会创建一个position &#x3D; 2, limit &#x3D; 5, capacity &#x3D; 10的Buffer；</p>
<p><img src="https://note.youdao.com/yws/api/personal/file/WEBca4ba5cc545b13c5408f971cf501543b?method=download&shareKey=37821de2d2cae1df33699c850e8195ac" alt="image"></p>
<h5 id="复制缓存区"><a href="#复制缓存区" class="headerlink" title="复制缓存区"></a>复制缓存区</h5><p>以下为复制缓存区的操作方法</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">public abstract CharBuffer duplicate(); </span><br><span class="line">public abstract CharBuffer asReadOnlyBuffer(); </span><br><span class="line">public abstract CharBuffer slice(); </span><br></pre></td></tr></table></figure>

<h6 id="duplicate"><a href="#duplicate" class="headerlink" title="duplicate()"></a>duplicate()</h6><blockquote>
<p>创建bytebuffer的浅拷贝,即数据共享,但是position&#x2F;limit&#x2F;cap&#x2F;capacity是相互独立的</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">ByteBuffer b1 = ByteBuffer.allocate(10);</span><br><span class="line">ByteBuffer b2=b1.duplicate();</span><br><span class="line">b1.put((byte) &#x27;M&#x27;).put((byte) &#x27;e&#x27;).put((byte) &#x27;l&#x27;).put((byte) &#x27;l&#x27;).put((byte) &#x27;o&#x27;).put((byte) &#x27;w&#x27;);</span><br><span class="line">b1.flip();</span><br><span class="line">while (b1.hasRemaining())&#123;</span><br><span class="line">    assert  b1.get()==b2.get();</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>上面运行结果会成功，因为b2与b1共享数据</p>
<h6 id="asReadOnlyBuffer"><a href="#asReadOnlyBuffer" class="headerlink" title="asReadOnlyBuffer()"></a>asReadOnlyBuffer()</h6><blockquote>
<p>与duplicate基本相同,只是创建的buffer的是只读,如果进行put元素会抛出ReadOnlyBufferException</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ByteBuffer b1 = ByteBuffer.allocate(10);</span><br><span class="line">ByteBuffer b2=b1.asReadOnlyBuffer();</span><br><span class="line">b2.put((byte)&#x27;s&#x27;);</span><br></pre></td></tr></table></figure>
<p>运行上面示例，会抛出ReadOnlyBufferException</p>
<h6 id="slice"><a href="#slice" class="headerlink" title="slice()"></a>slice()</h6><blockquote>
<p>sliece()其实是用于分割缓存区的，该方法创建了一个从原始缓冲区的当前位置开始的新缓冲区，并且其容量是原始缓冲区的剩余元素数量（limit-position)<br>该缓存区与原始缓存区共享一段序列</p>
</blockquote>
<p>创建一个容量为10的缓存区ByteBuffer</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ByteBuffer b = ByteBuffer.allocate(10);</span><br></pre></td></tr></table></figure>
<p><img src="https://note.youdao.com/yws/api/personal/file/WEB55d38dfd68692264ec794191d659d00e?method=download&shareKey=c6c2055041b830b3b0aa91a1e3a76b83" alt="image"></p>
<p>修改position&#x3D;2,limit&#x3D;5</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">charbuffer1.position(2).limit(5);</span><br></pre></td></tr></table></figure>
<p><img src="https://note.youdao.com/yws/api/personal/file/WEBca4ba5cc545b13c5408f971cf501543b?method=download&shareKey=37821de2d2cae1df33699c850e8195ac" alt="image"></p>
<p>调用charbuffer1.slice()方法，对charbuffer1进行分割</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">CharBuffer charbuffer2 = charbuffer1.slice();</span><br></pre></td></tr></table></figure>
<p>此时</p>
<ul>
<li>charbuffer1：mark &#x3D; -1; position &#x3D; 2; limit &#x3D; 5; capacity &#x3D; 10;</li>
<li>charbuffer2：mark &#x3D; -1; position &#x3D; 0; limit &#x3D; 3; capacity &#x3D; 3;</li>
</ul>
<p><img src="https://note.youdao.com/yws/api/personal/file/WEBb4670d1b10632a0d88fae3c0a18a286d?method=download&shareKey=eae42cf908d1e286a75f70258faec592" alt="image"></p>
<p>对应源码</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">public ByteBuffer slice() &#123;</span><br><span class="line">    return new HeapByteBuffer(hb,-1, 0,this.remaining(),this.remaining(),this.position() + offset);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="缓冲区视图"><a href="#缓冲区视图" class="headerlink" title="缓冲区视图"></a>缓冲区视图</h5><blockquote>
<p>byteBuffer类的另外一个常见的使用方式是在一个已有的ByteBuffer类的对象上创建出各种不同的视图。这些视图和它所基于的ByteBuffer类的对象共享同样的存储空间，但是提供额外的实用功能</p>
</blockquote>
<blockquote>
<p>最常见的ByteBuffer类的视图是转换成对基本数据类型进行操作的缓冲区对象。这些缓冲区包括CharBuffer、ShortBuffer、IntBuffer、LongBuffer、FloatBuffer和DoubleBuffer等Java类。从这些缓冲区的类名就可以知道所操作的数据类型。ByteBuffer类提供了对应的方法来完成相应的转换，如asIntBuffer方法在当前ByteBuffer类的对象的基础上创建一个新的IntBuffer类的视图。新创建的视图和原始的ByteBuffer类的对象所共享的不一定是全部的空间，而只是从ByteBuffer类的对象中的当前读写位置到读写限制之间的可用空间。在这个空间范围内，不论是在ByteBuffer类的对象中还是在作为视图的新缓冲区中，对数据所做的修改，对另一个来说都是可见的。除了数据本身之外，两者的读写位置、读写限制和标记位置等都是相互独立的。</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">public void viewBuffer() &#123;  </span><br><span class="line">    ByteBuffer buffer = ByteBuffer.allocate(32);  </span><br><span class="line">    buffer.putInt(1); //读取位置为4  </span><br><span class="line">    IntBuffer intBuffer = buffer.asIntBuffer();  </span><br><span class="line">    intBuffer.put(2);  </span><br><span class="line">    int value = buffer.getInt(); //值为2  </span><br><span class="line">&#125; </span><br></pre></td></tr></table></figure>
<h6 id="直接缓冲区"><a href="#直接缓冲区" class="headerlink" title="直接缓冲区"></a>直接缓冲区</h6><p><img src="https://note.youdao.com/yws/api/personal/file/WEB2f6f2e207cc731a6114a3ec937d1e7b2?method=download&shareKey=60ecb1618fd31fba97ebcfd8a7948102" alt="image"></p>
<blockquote>
<p>内核空间（与之相对的是用户空间，如 JVM）是操作系统所在区域，它能与设备控制器（硬件）通讯，控制着用户区域进程（如 JVM）的运行状态。最重要的是，所有的 I&#x2F;O 都直接（物理内存）或间接（虚拟内存）通过内核空间。 </p>
</blockquote>
<blockquote>
<p>从图中你可能会觉得，把数据从内核空间拷贝到用户空间似乎有些多余。为什么不直接让磁盘控制器把数据送到用户空间的缓冲区呢？首先，硬件通常不能直接访问用户空间。其次，像磁盘这样基于块存储的硬件设备操作的是固定大小的数据块，而用户进程请求的可能是任意大小的或非对齐的数据块。在数据往来于用户空间与存储设备的过程中，内核负责数据的分解、再组合工作，因此充当着中间人的角色。<br>        因此，操作系统是在内存区域中进行 I&#x2F;O 操作。这些内存区域，就操作系统方面而言，是相连的字节序列，这也意味着I&#x2F;O操作的目标内存区域必须是连续的字节序列。在 JVM中，字节数组可能不会在内存中连续存储（因为 JAVA 有 GC 机制），或者无用存储单元（会被垃圾回收）收集可能随时对其进行移动。 </p>
</blockquote>
<p>​        </p>
<blockquote>
<p>出于这个原因，引入了直接缓冲区的概念。直接字节缓冲区通常是 I&#x2F;O 操作最好的选择。非直接字节缓冲区（即通过 allocate() 或 wrap() 创建的缓冲区）可以被传递给通道，但是这样可能导致性能损耗。通常非直接缓冲不可能成为一个本地 I&#x2F;O 操作的目标。<br>        如果你向一个通道中传递一个非直接 ByteBuffer 对象用于写入，通道可能会在每次调用中隐含地进行下面的操作：</p>
</blockquote>
<ol>
<li>创建一个临时的直接 ByteBuffer 对象。</li>
<li>将非直接缓冲区的内容复制到临时直接缓冲区中。</li>
<li>使用临时直接缓冲区执行低层 I&#x2F;O 操作。</li>
<li>临时直接缓冲区对象离开作用域，并最终成为被回收的无用数据。<blockquote>
<p>这可能导致缓冲区在每个 I&#x2F;O 上复制并产生大量对象，而这种事都是我们极力避免的。如果你仅仅为一次使用而创建了一个缓冲区，区别并不是很明显。另一方面，如果你将在一段高性能脚本中重复使用缓冲区，分配直接缓冲区并重新使用它们会使你游刃有余。<br>     直接缓冲区可能比创建非直接缓冲区要花费更高的成本，它使用的内存是通过调用本地操作系统方面的代码分配的，绕过了标准 JVM 堆栈，不受垃圾回收支配，因为它们位于标准 JVM 堆栈之外。<br>     直接 ByteBuffer 是通过调用具有所需容量的 ByteBuffer.allocateDirect() 函数产生的。注意，wrap() 函数所创建的被包装的缓冲区总是非直接的</p>
</blockquote>
</li>
</ol>
<p>参考：</p>
<p><a target="_blank" rel="noopener" href="http://blog.csdn.net/aiwuzhi12/article/details/60319642">Java NIO中的缓冲区Buffer（二）创建-复制缓冲区</a></p>
<p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/lxzh/archive/2013/05/10/3071680.html">Buffer类的详解(转)</a></p>

        
            <div id="toc-article">
                
  <div class="widget-wrap" id="toc-wrap">
    <h3 class="widget-title"><i class="fa fa-toc"></i> 文章目录</h3>
    <div class="widget">
      <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B1%9E%E6%80%A7"><span class="toc-text">属性</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#%E5%AE%B9%E9%87%8F-Capacity"><span class="toc-text">容量(Capacity)</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E4%B8%8A%E7%95%8C-Limit"><span class="toc-text">上界(Limit)</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E4%BD%8D%E7%BD%AE-Position"><span class="toc-text">位置(Position)</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E6%A0%87%E8%AE%B0-Mark"><span class="toc-text">标记(Mark)</span></a></li></ol></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%96%B9%E6%B3%95"><span class="toc-text">方法</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#flip"><span class="toc-text">flip()</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#rewind"><span class="toc-text">rewind()</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#hasRemaining"><span class="toc-text">hasRemaining()</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%B8%85%E7%A9%BA%E7%BC%93%E5%86%B2%E5%8C%BA"><span class="toc-text">清空缓冲区</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#clear"><span class="toc-text">clear()</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#Compact"><span class="toc-text">Compact()</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%AF%94%E8%BE%83"><span class="toc-text">比较</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#equals"><span class="toc-text">equals()</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#compareToTest"><span class="toc-text">compareToTest()</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%AD%98%E5%8F%96%E5%85%83%E7%B4%A0"><span class="toc-text">存取元素</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#get-byte-dst"><span class="toc-text">get(byte[] dst)</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#get-byte-dst-int-offset-int-length"><span class="toc-text">get(byte[] dst, int offset, int length)</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#put-byte-src"><span class="toc-text">put(byte [] src)</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#put-byte-src-int-offset-int-length"><span class="toc-text">put(byte[] src, int offset, int length) {</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E7%BC%93%E5%86%B2%E5%8C%BA"><span class="toc-text">创建缓冲区</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#allocate-int-capacity"><span class="toc-text">allocate (int capacity)</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#wrap-byte-array"><span class="toc-text">wrap(byte[] array)</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#wrap-byte-array-int-offset-int-length"><span class="toc-text">wrap(byte[] array, int offset, int length)</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%A4%8D%E5%88%B6%E7%BC%93%E5%AD%98%E5%8C%BA"><span class="toc-text">复制缓存区</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#duplicate"><span class="toc-text">duplicate()</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#asReadOnlyBuffer"><span class="toc-text">asReadOnlyBuffer()</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#slice"><span class="toc-text">slice()</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E7%BC%93%E5%86%B2%E5%8C%BA%E8%A7%86%E5%9B%BE"><span class="toc-text">缓冲区视图</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#%E7%9B%B4%E6%8E%A5%E7%BC%93%E5%86%B2%E5%8C%BA"><span class="toc-text">直接缓冲区</span></a></li></ol></li></ol></li></ol>
    </div>
  </div>


            </div>
        
        
          <blockquote id="copyright">
              <p>原文链接: <a href="https://dongweizhao.github.io/2018/01/26/2022/java/Buffer/">https://dongweizhao.github.io/2018/01/26/2022/java/Buffer/</a></p>
              <p>版权声明: 转载请注明出处.</p>
          </blockquote>
        
      
    </div>
    <footer class="article-footer">
      
        <div class="article-tag-wrap">
          

          
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/nio/" rel="tag">nio</a></li></ul>

          
    <div class="social-share">
      <span>分享到:</span>
    </div>



        </div>
      
      
        
<nav id="article-nav">
  
    <a href="/2018/01/17/2022/java/%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%88%86%E6%9E%90/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">older</strong>
      <div class="article-nav-title">
        
          线程池的创建与销毁分析
        
      </div>
    </a>
  
  
    <a href="/2018/02/11/2022/%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E9%97%B4%E4%BB%B6/%E9%93%BE%E8%A1%A8%E7%9A%84%E6%95%B0%E6%8D%AE%E4%B8%A4%E4%B8%A4%E4%BA%A4%E6%8D%A2/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">newer</strong>
      <div class="article-nav-title">
        
          链表的数据两两交换
        
      </div>
    </a>
  
</nav>

      
      
        








      
    </footer>
  </div>
</article>
</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-posts"></i> 最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2023/12/17/2023/%E4%BA%91%E5%8E%9F%E7%94%9F/%E5%9F%BA%E4%BA%8EK8S%E7%A7%81%E6%9C%89%E5%8C%96%E4%BA%A4%E4%BB%98%E8%A6%81%E6%B3%A8%E6%84%8F%E5%87%A0%E7%82%B9%E9%97%AE%E9%A2%98/">基于K8S私有化交付要注意几点问题</a>
          </li>
        
          <li>
            <a href="/2023/12/17/2023/%E4%BA%91%E5%8E%9F%E7%94%9F/%E4%BB%8E%E7%89%A9%E7%90%86%E6%9C%BA%E5%88%B0K8S%EF%BC%9A%E5%BA%94%E7%94%A8%E7%B3%BB%E7%BB%9F%E9%83%A8%E7%BD%B2%E6%96%B9%E5%BC%8F%E7%9A%84%E6%BC%94%E8%BF%9B%E5%8F%8A%E5%85%B6%E5%BD%B1%E5%93%8D/">从物理机到K8S：应用系统部署方式的演进及其影响</a>
          </li>
        
          <li>
            <a href="/2023/12/17/2023/%E4%BA%91%E5%8E%9F%E7%94%9F/%E4%BB%80%E4%B9%88%E6%98%AF%E9%9D%A9%E5%91%BD%E6%80%A7%E6%8A%80%E6%9C%AFeBPF%EF%BC%9F%E4%B8%BA%E4%BB%80%E4%B9%88%E5%8F%AF%E8%A7%82%E6%B5%8B%E6%80%A7%E9%A2%86%E5%9F%9F%E9%83%BD%E5%BE%97%E7%94%A8%E5%AE%83/">什么是革命性技术eBPF？为什么可观测性领域都得用它</a>
          </li>
        
          <li>
            <a href="/2023/12/17/2023/%E4%BA%91%E5%8E%9F%E7%94%9F/%E5%A6%82%E4%BD%95%E5%9F%BA%E4%BA%8E%20k8s%E5%81%9A%E7%A7%81%E6%9C%89%E5%8C%96%E9%83%A8%E7%BD%B2/">如何基于 k8s做私有化部署</a>
          </li>
        
          <li>
            <a href="/2023/12/17/2023/%E4%BA%91%E5%8E%9F%E7%94%9F/10%E4%B8%AA%E5%B8%B8%E8%A7%81%E7%9A%84%20Kubernetes%20%E9%99%B7%E9%98%B1%E5%92%8C%E6%8C%91%E6%88%98/">10个常见的 Kubernetes 陷阱和挑战</a>
          </li>
        
      </ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-tag"></i> 标签云</h3>
    <div class="widget tagcloud">
      <a href="/tags/AI/" style="font-size: 10px;">AI</a> <a href="/tags/AIGC/" style="font-size: 10px;">AIGC</a> <a href="/tags/Kubernetes/" style="font-size: 17.5px;">Kubernetes</a> <a href="/tags/Stream/" style="font-size: 10px;">Stream</a> <a href="/tags/chatGPT/" style="font-size: 10px;">chatGPT</a> <a href="/tags/eBPF/" style="font-size: 10px;">eBPF</a> <a href="/tags/java/" style="font-size: 15px;">java</a> <a href="/tags/k8s/" style="font-size: 12.5px;">k8s</a> <a href="/tags/k8s10-%E4%B8%AA%E5%B8%B8%E8%A7%81%E6%8C%91%E6%88%98%E5%92%8C%E9%99%B7%E9%98%B1/" style="font-size: 10px;">k8s10 个常见挑战和陷阱</a> <a href="/tags/nio/" style="font-size: 10px;">nio</a> <a href="/tags/%E4%BB%80%E4%B9%88%E6%98%AFeBPF/" style="font-size: 10px;">什么是eBPF</a> <a href="/tags/%E4%BB%8Edocker%E5%88%B0k8s/" style="font-size: 10px;">从docker到k8s</a> <a href="/tags/%E5%88%86%E5%B8%83%E5%BC%8F/" style="font-size: 17.5px;">分布式</a> <a href="/tags/%E5%88%86%E5%BA%93%E5%88%86%E8%A1%A8%E5%8F%8A%E4%BA%8B%E5%8A%A1%E4%B8%80%E8%87%B4%E6%80%A7%E8%AE%BE%E8%AE%A1/" style="font-size: 17.5px;">分库分表及事务一致性设计</a> <a href="/tags/%E5%8F%AF%E8%A7%82%E6%B5%8B%E9%A2%86%E5%9F%9F%E5%BA%95%E5%B1%82%E6%8A%80%E6%9C%AF/" style="font-size: 10px;">可观测领域底层技术</a> <a href="/tags/%E5%90%8E%E7%AB%AF/" style="font-size: 10px;">后端</a> <a href="/tags/%E5%A6%82%E4%BD%95%E5%9F%BA%E4%BA%8E-k8s%E5%81%9A%E7%A7%81%E6%9C%89%E5%8C%96%E9%83%A8%E7%BD%B2/" style="font-size: 10px;">如何基于 k8s做私有化部署</a> <a href="/tags/%E5%B9%B6%E5%8F%91/" style="font-size: 15px;">并发</a> <a href="/tags/%E6%9E%B6%E6%9E%84%E6%88%90%E9%95%BF%E6%8C%87%E5%8D%97/" style="font-size: 20px;">架构成长指南</a> <a href="/tags/%E7%A7%81%E6%9C%89%E5%8C%96%E4%BA%A4%E4%BB%98/" style="font-size: 10px;">私有化交付</a> <a href="/tags/%E7%A7%81%E6%9C%89%E5%8C%96%E9%83%A8%E7%BD%B2/" style="font-size: 12.5px;">私有化部署</a> <a href="/tags/%E7%B3%BB%E7%BB%9F%E9%83%A8%E7%BD%B2%E6%9E%B6%E6%9E%84%E6%BC%94%E8%BF%9B/" style="font-size: 10px;">系统部署架构演进</a> <a href="/tags/%E9%93%BE%E8%A1%A8/" style="font-size: 12.5px;">链表</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-classify"></i> 分类</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/">云原生</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%90%8E%E7%AB%AF/">后端</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%B7%A5%E5%85%B7/">工具</a><span class="category-list-count">1</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%B7%A5%E5%85%B7/AI/">AI</a><span class="category-list-count">1</span></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E7%AE%97%E6%B3%95/">算法</a><span class="category-list-count">2</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-archive"></i>公众号</h3>
    <div class="widget">
       <img src="/gzh.jpg" style="width:80%; height:80%;" />
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-tag"></i> 标签</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/AI/" rel="tag">AI</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/AIGC/" rel="tag">AIGC</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Kubernetes/" rel="tag">Kubernetes</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Stream/" rel="tag">Stream</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/chatGPT/" rel="tag">chatGPT</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/eBPF/" rel="tag">eBPF</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/" rel="tag">java</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/k8s/" rel="tag">k8s</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/k8s10-%E4%B8%AA%E5%B8%B8%E8%A7%81%E6%8C%91%E6%88%98%E5%92%8C%E9%99%B7%E9%98%B1/" rel="tag">k8s10 个常见挑战和陷阱</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nio/" rel="tag">nio</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E4%BB%80%E4%B9%88%E6%98%AFeBPF/" rel="tag">什么是eBPF</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E4%BB%8Edocker%E5%88%B0k8s/" rel="tag">从docker到k8s</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%88%86%E5%B8%83%E5%BC%8F/" rel="tag">分布式</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%88%86%E5%BA%93%E5%88%86%E8%A1%A8%E5%8F%8A%E4%BA%8B%E5%8A%A1%E4%B8%80%E8%87%B4%E6%80%A7%E8%AE%BE%E8%AE%A1/" rel="tag">分库分表及事务一致性设计</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8F%AF%E8%A7%82%E6%B5%8B%E9%A2%86%E5%9F%9F%E5%BA%95%E5%B1%82%E6%8A%80%E6%9C%AF/" rel="tag">可观测领域底层技术</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%90%8E%E7%AB%AF/" rel="tag">后端</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%A6%82%E4%BD%95%E5%9F%BA%E4%BA%8E-k8s%E5%81%9A%E7%A7%81%E6%9C%89%E5%8C%96%E9%83%A8%E7%BD%B2/" rel="tag">如何基于 k8s做私有化部署</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B9%B6%E5%8F%91/" rel="tag">并发</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9E%B6%E6%9E%84%E6%88%90%E9%95%BF%E6%8C%87%E5%8D%97/" rel="tag">架构成长指南</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%A7%81%E6%9C%89%E5%8C%96%E4%BA%A4%E4%BB%98/" rel="tag">私有化交付</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%A7%81%E6%9C%89%E5%8C%96%E9%83%A8%E7%BD%B2/" rel="tag">私有化部署</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%B3%BB%E7%BB%9F%E9%83%A8%E7%BD%B2%E6%9E%B6%E6%9E%84%E6%BC%94%E8%BF%9B/" rel="tag">系统部署架构演进</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E9%93%BE%E8%A1%A8/" rel="tag">链表</a><span class="tag-list-count">2</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-link"></i> 友情链接</h3>
    <div class="widget">
      <ul>
      
        <li>
          <a target="_blank" rel="noopener" href="https://juejin.cn/user/1292681402913080">我的掘金</a>
        </li>
      
        <li>
          <a target="_blank" rel="noopener" href="https://www.zhihu.com/people/dong-wei-zhao-73">我的知乎</a>
        </li>
      
        <li>
          <a target="_blank" rel="noopener" href="https://blog.csdn.net/dweizhao?type=blog">我的CSDN</a>
        </li>
      
      </ul>
    </div>
  </div>


  
</aside>
        
      </div>
      <a id="totop" href="#top"></a>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      <p>
        <a href="/sitemap.xml">网站地图</a>
        <span> | </span><a href="/atom.xml">订阅本站</a>
        <span> | </span><a href="/about/">联系博主</a>
      </p>
      
        <p>
          <i class="fa fa-visitors"></i>
          <i id="busuanzi_container_site_uv"><i id="busuanzi_value_site_uv"></i></i>
          ，
          <i class="fa fa-views"></i>
          <i id="busuanzi_container_site_pv"><i id="busuanzi_value_site_pv"></i></i>
        </p>
      
      <p>
        <span>Copyright &copy; 2023 架构成长指南.</span>
        <span>Theme by <a href="https://github.com/chaooo/hexo-theme-BlueLake/" target="_blank">BlueLake.</a></span>
        <span>Powered by <a href="https://hexo.io/" target="_blank">Hexo.</a></span>
      </p>
    </div>
  </div>
</footer>

    </div>
  </div>
  
<script src="/js/jquery-3.4.1.min.js"></script>


<script src="/js/search.json.js"></script>


  
<script src="/fancybox/jquery.fancybox.min.js"></script>




<script src="/js/script.js"></script>






  
<script src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




  
    
<script src="/localshare/js/social-share.js"></script>

    
<script src="/localshare/js/qrcode.js"></script>

  
  



  

  

  

  

  

  

  

  
  





</body>
</html>